﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agile.Engine.View;

namespace Fis.Win.Rules
{
    public class ClientViewProvider : ProxyViewProvider
    {
        public override bool InvokeService(System.Collections.Hashtable args)
        {
            if (Fis.Win.Utils.AppSession.IsNetConnect)
            {
                Proxy = Fis.Win.Utils.AppConfig.CreateProxyInstance();
                var result = base.InvokeService(args);
                ResetCache();
                return result;
            }
            else
            {
                Message = ServiceProcess.Message = "网络连接失败,请先连接到云服务";
            }
            return false;
        }

        void ResetCache()
        {
            if (ServiceProcess.Status == -2)
            {
                var cachedata = Agile.Engine.Utils.ZipUtils.UnZipBase64(ServiceProcess.Result["cache"].ToString());
                Agile.Engine.Utils.IOUtils.WriteStream(cachedata, string.Format("{0}/cache.sdf", Agile.Engine.ObjectContext.Environment.Config));
                Fis.Win.Utils.AppSession.InitializeBookInfo();
                DevExpress.XtraBars.Alerter.AlertControl alert
                     = new DevExpress.XtraBars.Alerter.AlertControl();
                alert.Show(Fis.Win.Utils.UIUtils.MainForm, "提示", ServiceProcess.Message);
            }
        }
    }
}
